venv dist-packages site-packages
Source
-
by default, python will only have access to the
site-packagesdirectly installed inside a venv -
if we want to access the packages from the (Linux) system’s
dist-packagesthat were installed using the system’s package manager, there are multiple possible ways- set
PYTHONPATHto include/usr/lib/python<VERSION>/dist-packagesthis has the drawback that now thedist-packagestake precedence over thesite-packagesfrom the venv, thus if we have the same package installed in the venv but with a different (usually more recent) version than in thedist-packages, python will use the one from thedist-packages, which is usually not what we want - create a
.pthfile in the venv’ssite-packagesfolder that points to the system’sdist-packagesthis has the advantage, that the venv’s packages will be used first and only if python cannot find a package in the venv, it will go looking into the system’sdist-packages
echo "/usr/lib/python<VERSION>/dist-packages" > .venv/lib/python<VERSION>/site-packages/dist-packages.pth(the
<VERSION>has to match, of course, so for Python 3.10, for example, this would readpython3.10in both cases) - set